<?php
function adds( )
{ 
				echo "<script language=\"javascript\" src=\"inc/js.js\"></script>\r\n<table width=\"98%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" class=\"table\">\r\n <form action=\"Admin_Columns_Set.php?Action=add\" method=\"post\" name=\"form\" onSubmit=\"return Validator.Validate(this,3)\">\r\n <input name=\"id\" type=\"hidden\" value=\"";
								echo $db->Record['id'];
								echo "\" />\r\n  <tr>\r\n    <td width=\"15%\" align=\"right\">所属栏目：</td>\r\n    <td>\r\n   ";
								echo" <select  name=\"bid\" dataType=\"Require\" msg=\"请选择内容\">";
                                echo"<option value=\"0\">-----顶级分类-----</option>";
            	                dafenglei_select(0,0,"".$_GET['bid']."");
	                            echo"</select>";
								echo "</td>\r\n  </tr>\r\n  <tr>\r\n    <td align=\"right\">栏目名称：</td>\r\n    <td><input name=\"columnsname\" type=\"text\" value=\"";
								echo $db->Record['columnsname'];
								echo "\" size=\"50\" dataType=\"Require\" msg=\"请填栏目名称\"/></td>\r\n  </tr>\r\n  <tr>\r\n    <td align=\"right\">是否隐藏：</td>\r\n    <td>";
								echo "<input type=\"radio\" name=\"hide\" value=\"0\" checked=\"checked\">正常显示 <input type=\"radio\" name=\"hide\" value=\"1\">隐藏栏目";
								echo "</td>\r\n  </tr>\r\n<tr>\r\n    <td align=\"right\">所属模块：</td>\r\n    <td>";
								eidtmodule($db->Record['module']);
								echo "\r\n</td></tr>\r\n <tr>\r\n    <td align=\"right\">模版名：</td>\r\n    <td><input name=\"templates\" type=\"text\" value=\"";
								echo "\" size=\"30\"/>*请直接输入英文或数字，例如你填写了<font color=red>T</font>，则栏目页调用<font color=red>T</font>.htm，内容页调用view_<font color=red>T</font>.htm。若为空，则使用默认模版</td>\r\n  </tr><input name=\"turl\" type=\"hidden\" value=\"";
								echo $db->Record['turl'];
								echo "\"/>\r\n  <tr>\r\n    <td align=\"right\" valign=\"top\">栏目描述：</td>\r\n    <td><textarea name=\"description\" style=\"width:50%\" rows=\"10\" id=\"introduction\">";
								echo $db->Record['description'];
								echo "</textarea></td>\r\n  </tr>\r\n  <tr>\r\n    <td align=\"right\" valign=\"top\">栏目关键字：</td>\r\n    <td>关键字间用英文的逗号隔开,设置后易被搜索引擎收录<br/> <textarea name=\"keywords\" style=\"width:50%\" rows=\"10\" id=\"introduction\">";
								echo $db->Record['keywords'];
								echo "</textarea></td>\r\n  </tr>\r\n  <input name=\"content\" type=\"hidden\" value=\"";
								echo $db->Record['content'];
								echo "\" />\r\n   <tr>\r\n    <td align=\"right\">栏目排序：</td>\r\n    <td><input name=\"columnswith\" id=\"columnswith\" value=\"0"; 

								echo "\" size=\"10\" dataType=\"Integer\" msg=\"请填栏目排序\"/>\r\n[ 请添加数字,数值越大排序越前 ]</td></tr><tr>\r\n    <td colspan=\"2\" align=\"center\"><input name=\"url\" type=\"hidden\" value=\"";
								echo $_SERVER['HTTP_REFERER'];
								echo "\"><input type=\"submit\" name=\"Submit_edit\" value=\"添加\" id=\"Submit_edit\" /></td>\r\n  </tr>\r\n </form>\r\n</table>\r\n<br>\r\n";
}

function edits( )
{
				global $db;
				$db->query( "select * from tun2_columns WHERE id=".$_GET['id'] );
				if ( $db->next_record( ) )
				{
								echo "<script language=\"javascript\" src=\"inc/js.js\"></script>\r\n<table width=\"98%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" class=\"table\">\r\n <form action=\"Admin_Columns_Set.php?Action=edit\" method=\"post\" name=\"form\" onSubmit=\"return Validator.Validate(this,3)\">\r\n <input name=\"id\" type=\"hidden\" value=\"";
								echo $db->Record['id'];
								echo "\" />\r\n  <tr>\r\n    <td width=\"15%\" align=\"right\">所属栏目：</td>\r\n    <td>\r\n   ";
								echo" <select  name=\"bid\" dataType=\"Require\" msg=\"请选择内容\">";
                                echo"<option value=\"0\">-----顶级分类-----</option>";
            	                dafenglei_select(0,0,"".$_GET['bid']."");
	                            echo"</select>";
								echo "</td>\r\n  </tr>\r\n  <tr>\r\n    <td align=\"right\">栏目名称：</td>\r\n    <td><input name=\"columnsname\" type=\"text\" value=\"";
								echo $db->Record['columnsname'];
								echo "\" size=\"50\" dataType=\"Require\" msg=\"请填栏目名称\"/></td>\r\n  </tr>\r\n  <tr>\r\n    <td align=\"right\">是否隐藏：</td>\r\n    <td>";
								if ($db->Record['hide']==0)
								{
									echo "<input type=\"radio\" name=\"hide\" value=\"0\" checked=\"checked\">正常显示 <input type=\"radio\" name=\"hide\" value=\"1\">隐藏栏目";
								} else if ($db->Record['hide']==1)
								{
									echo "<input type=\"radio\" name=\"hide\" value=\"0\">正常显示 <input type=\"radio\" name=\"hide\" value=\"1\" checked=\"checked\">隐藏栏目";
									}
								echo "</td>\r\n  </tr>\r\n<tr>\r\n    <td align=\"right\">所属模块：</td>\r\n    <td>";
								eidtmodule($db->Record['module']);
								echo "\r\n</td></tr>\r\n <tr>\r\n    <td align=\"right\">模版名：</td>\r\n    <td><input name=\"templates\" type=\"text\" value=\"";
								echo $db->Record['templates'];
								echo "\" size=\"30\"/>*请直接输入英文或数字，例如你填写了<font color=red>T</font>，则栏目页调用<font color=red>T</font>.htm，内容页调用view_<font color=red>T</font>.htm。若为空，则使用默认模版</td>\r\n  </tr><input name=\"turl\" type=\"hidden\" value=\"";
								echo $db->Record['turl'];
								echo "\" /><tr>\r\n    <td align=\"right\" valign=\"top\">栏目描述：</td>\r\n    <td><textarea name=\"description\" style=\"width:50%\" rows=\"10\" id=\"introduction\">";
								echo $db->Record['description'];
								echo "</textarea></td>\r\n  </tr>\r\n  <tr>\r\n    <td align=\"right\" valign=\"top\">栏目关键字：</td>\r\n    <td>关键字间用英文的逗号隔开,设置后易被搜索引擎收录<br/><textarea name=\"keywords\" style=\"width:50%\" rows=\"10\" id=\"introduction\">";
								echo $db->Record['keywords'];
								echo "</textarea></td>\r\n  </tr>\r\n<textarea name=\"content\"  style=\"width:0;height:0;\">";
								echo $db->Record['content'];
								echo "</textarea><tr>\r\n    <td align=\"right\">栏目排序：</td>\r\n    <td><input name=\"columnswith\" id=\"columnswith\" value=\""; 
								echo $db->Record['columnswith'];
								echo "\" size=\"10\" dataType=\"Integer\" msg=\"请填栏目排序\"/>\r\n[ 请添加数字,数值越大排序越前 ]</td></tr><tr>\r\n    <td colspan=\"2\" align=\"center\"><input name=\"url\" type=\"hidden\" value=\"";
								echo $_SERVER['HTTP_REFERER'];
								echo "\"><input type=\"submit\" name=\"Submit_edit\" value=\"修改\" id=\"Submit_edit\" /></td>\r\n  </tr>\r\n </form>\r\n</table>\r\n<br>\r\n";
				}
}



include( "inc/header.php" );
login_check( );
$class_arr=array();
$sql = "select * from `tun2_columns` order by columnswith desc, id Desc";
$query = $db -> query($sql);
while($row=mysql_fetch_assoc($query)){
              $class_arr[] = array($row['id'],$row['columnsname'],$row['bid'],$row['sort']);
		}
echo "\r\n<body>\r\n";
switch ( $_REQUEST['Action'] )
{
case "adds" :
				adds( );
				break;
case "add" :
				if ( function_exists( "date_default_timezone_set" ) )
				{
								date_default_timezone_set( "Hongkong" );
				}

				$db->query( "INSERT INTO tun2_columns (bid,module,templates,turl,columnsname,hide,description,keywords,columnswith,content) VALUES ('".$_POST['bid']."','{$_POST['module']}','{$_POST['templates']}','{$_POST['turl']}','{$_POST['columnsname']}','{$_POST['hide']}','{$_POST['description']}','{$_POST['keywords']}','{$_POST['columnswith']}','{$_POST['content']}')" );
				addlog( "添加栏目", $_SESSION['user_name'] );
				admin_showerr( "<li>添加栏目成功</li>", "Admin_Columns.php", 1 );
				break;
case "edits" :
				edits( );
				break;
case "editall" :
				editall( );
				break;
case "edit" :
				if ( function_exists( "date_default_timezone_set" ) )
				{
								date_default_timezone_set( "Hongkong" );
				}
				$addtime = date( "Y-m-d H-i-s" );
				extract( $_POST );

				$db->query( "UPDATE tun2_columns SET bid='".$_POST['bid']."',\r\n\t\tmodule='{$_POST['module']}',\r\n\t\ttemplates='{$_POST['templates']}',\r\n\t\tturl='{$_POST['turl']}',\r\n\t\tcolumnsname='{$_POST['columnsname']}',\r\n\t\thide='{$_POST['hide']}',\r\n\t\tdescription='{$_POST['description']}',\r\n\t\tkeywords='{$_POST['keywords']}',\r\n\t\tcolumnswith='{$_POST['columnswith']}',\r\n\t\tcontent='{$_POST['content']}'  WHERE id={$_POST['id']}" );
				
				addlog( "修改栏目", $_SESSION['user_name'] );
				admin_showerr( "<li>修改栏目成功</li>", $_POST['url'], 1 );
				break;

case "del" :
if ( isset( $_POST['id'] ) )
				{
								$chid = implode( ",", $_POST['id'] );
				}
				else
				{
								$chid = $_GET['id'];
				}
       $result = mysql_query("SELECT * FROM tun2_columns where bid='".$chid."' ");
       $row = mysql_fetch_array($result);
       if(empty($row[0]))
          {
			  $result = mysql_query("SELECT * FROM tun2_content where columnsname='".$chid."' ");
              $row = mysql_fetch_array($result);
              if(empty($row[0]))
			  {
			  $db->query( "DELETE FROM tun2_columns WHERE id IN (".$chid.")" );
				addlog( "删除栏目", $_SESSION['user_name'] );
				admin_showerr( "<li>删除栏目成功</li>", $_SERVER['HTTP_REFERER'], 1 );
				break;
				$db->query( "UPDATE tun2_columns set ".$_GET['Action']."={$_GET['value']} WHERE id={$_GET['id']}" );
				addlog( "修改栏目属性", $_SESSION['user_name'] );
				header( "Location:".$_SERVER['HTTP_REFERER'] );
			  }
			  else
			  {
				  echo "<SCRIPT language=JavaScript>alert('此栏目有内容，无法删除');javascript:history.go(-1);</SCRIPT>";
			  }
		  }
		  else
		  {
				echo "<SCRIPT language=JavaScript>alert('存在子栏目，无法删除');javascript:history.go(-1);</SCRIPT>";
		  }
				break;
default :


       
		} 

?>